using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using My.ExcelToData.ExcelDatas;
using My.ExcelToData.ExcelDatas.Dtos;
using My.ExcelToData.Web.Pages.ExcelDatas.ExcelData.ViewModels;

namespace My.ExcelToData.Web.Pages.ExcelDatas.ExcelData;

public class CreateModalModel : ExcelToDataPageModel
{
    [BindProperty]
    public CreateEditExcelDataViewModel ViewModel { get; set; }

    private readonly IExcelDataAppService _service;

    public CreateModalModel(IExcelDataAppService service)
    {
        _service = service;
    }

    public virtual async Task<IActionResult> OnPostAsync()
    {
        var dto = ObjectMapper.Map<CreateEditExcelDataViewModel, CreateUpdateExcelDataDto>(ViewModel);
        await _service.CreateAsync(dto);
        return NoContent();
    }
}